Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow to build package and run tests #8

Merged
merged 15 commits into from
Aug 5, 2024

Conversation

sarpsahinalp
Copy link
Collaborator

@sarpsahinalp sarpsahinalp commented Jul 14, 2024

Checklist

General

Ares

  • I documented the Java code using JavaDoc style.

Motivation and Context

This PR solves a bug within the ArchRules that was not detected due to abstract and interface classes. It changes the ClassLoader to import all related classes to be able to retrieve the necessary metadata for the architectural tests. It also introduces a CI workflow to be able to see if some things broke the tests.

Description

Introduced a new CI workflow for building and testing Ares2.0. Modified formatVertexInfoWithinCycle to use File.separator for improved OS compatibility. Removed explicit class resolver setting, reverting to default resolution. Enhanced method access management with bannedClasses.

  • Bug Fixes

    • Enhanced clarity and adherence to naming conventions in enumerations.
  • Documentation

    • Added comprehensive architectural rules definitions in new files.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Summary by CodeRabbit

  • New Features

    • Introduced a Continuous Integration workflow for Java projects using Maven, automating the build and test process on code changes.
    • Added a new logger configuration for improved logging capabilities related to the ArchUnit package.
    • Configured ArchUnit to ignore missing dependencies and allow architectural rules to pass without corresponding tests.
  • Bug Fixes

    • Improved compatibility of file path handling across different operating systems.
  • Improvements

    • Enhanced the class resolution process for better flexibility and efficiency.
  • Chores

    • Simplified access permissions in tests by removing the security policy annotation.

Summary by CodeRabbit

  • New Features

    • Introduced Continuous Integration workflow for Java projects using Maven, automating build and test processes.
    • Added configuration settings for ArchUnit to enhance architectural testing flexibility.
    • Implemented refined logic for method access condition checks, excluding certain classes from violations.
  • Bug Fixes

    • Improved class resolution handling to enhance efficiency in access checks.
  • Documentation

    • Added logger configuration for improved observability of ArchUnit components.

@sarpsahinalp sarpsahinalp linked an issue Jul 14, 2024 that may be closed by this pull request
@sarpsahinalp sarpsahinalp self-assigned this Jul 15, 2024
Copy link
Collaborator

@az108 az108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

Copy link
Contributor

coderabbitai bot commented Jul 28, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

A new Continuous Integration (CI) workflow for Java projects using Maven automates builds and tests on changes to the main branch. Enhancements to the CustomClassResolver and TransitivelyAccessesMethodsCondition improve class resolution and access checks. The introduction of archunit.properties configures architectural testing, while logging capabilities have been expanded with a new logger for the ArchUnit package, enhancing observability without disrupting existing functionality.

Changes

Files Change Summary
.github/workflows/maven.yml Introduced a new CI workflow for Java projects utilizing Maven.
src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java
src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java
Refactored classes to enhance flexibility in class resolution and access checks.
src/main/resources/archunit.properties Added configurations for ArchUnit to manage dependency resolution and rule enforcement.
src/main/resources/logback.xml Added a logger for com.tngtech.archunit with level set to INFO.

Poem

In the code we hop and play,
With Maven on our way,
Builds now swift, tests in line,
Java joy, how we shine!
🌟🐇
A workflow fresh, we greet the day!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5d7c9d1 and 5fb4d21.

Files selected for processing (1)
  • .github/workflows/maven.yml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/maven.yml

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5fb4d21 and 9afa670.

Files selected for processing (3)
  • src/main/java/de/tum/cit/ase/ares/api/ast/model/RecursionCheck.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/AstAssertionTest.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/PathAccessUser.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/main/java/de/tum/cit/ase/ares/api/ast/model/RecursionCheck.java
  • src/test/java/de/tum/cit/ase/ares/integration/AstAssertionTest.java
Additional comments not posted (1)
src/test/java/de/tum/cit/ase/ares/integration/testuser/PathAccessUser.java (1)

Line range hint 69-69:
Verify the intentional removal of the security policy.

The @Policy annotation, which specified a security policy file and a path constraint, has been removed from the weAccessPath method. Ensure that this change is intentional and does not compromise the security context of the test.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9afa670 and 590fdd2.

Files selected for processing (1)
  • .github/workflows/maven.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/maven.yml

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 590fdd2 and 4ee9d55.

Files selected for processing (8)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (2 hunks)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java (3 hunks)
  • src/main/resources/archunit.properties (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/PathAccessTest.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/PathAccessUser.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/pathaccess/PathAccessPenguin.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/student/FileSystemAccessPenguin.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/thirdpartypackage/ThirdPartyPackagePenguin.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/main/resources/archunit.properties
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/pathaccess/PathAccessPenguin.java
Files skipped from review as they are similar to previous changes (1)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/PathAccessUser.java
Additional comments not posted (19)
src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/thirdpartypackage/ThirdPartyPackagePenguin.java (1)

15-17: Verify the existence of the file during tests.

Ensure that the file fileUsingFilesClass.txt exists in the expected location during tests to avoid FileNotFoundException.

src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (1)

Line range hint 1-24:
Verify the impact of the removed class resolver setting.

The removal of the line ArchConfiguration.get().setClassResolver(ClassResolverFromClasspath.class); might affect the class resolution mechanism. Ensure that the class resolution process works as expected without this setting.

src/test/java/de/tum/cit/ase/ares/integration/PathAccessTest.java (1)

103-106: Verify the exception handling during the test.

Ensure that the SecurityException is correctly handled and reported during the test.

Verification successful

Verify the exact implementation of the test_accessFileSystem method.

Ensure that the method correctly handles and asserts the SecurityException.


Exception handling in test_accessFileSystem is correctly implemented.

The method correctly asserts that a SecurityException is thrown when accessing the file system.

  • src/test/java/de/tum/cit/ase/ares/integration/PathAccessTest.java: test_accessFileSystem
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the exception handling during the test.

# Test: Search for the `SecurityException` handling. Expect: Proper handling of the exception.
rg --type java 'SecurityException'

Length of output: 19328


Script:

#!/bin/bash
# Description: Retrieve the implementation of the `test_accessFileSystem` method to verify exception handling.

# Search for the `test_accessFileSystem` method in the PathAccessTest.java file.
rg --type java '@TestTest' -A 5

Length of output: 206213

src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java (5)

15-15: Imports look good.

The addition of java.util.* is necessary for the new functionality.


30-38: Addition of bannedClasses is appropriate.

This set refines the criteria for determining access violations by excluding certain fundamental Java classes and packages from consideration.


50-54: Addition of resolvedClasses is appropriate.

This map optimizes performance by caching resolved classes and preventing redundant resolution attempts.


61-61: Initialization of resolvedClasses is appropriate.

Initializing the map as a HashMap ensures it is ready for use.


166-178: Changes to getDirectAccessTargetsOutsideOfAnalyzedClasses are appropriate.

The method now checks if the accessed class is part of bannedClasses and uses resolvedClasses to optimize class resolution, enhancing efficiency and ensuring adherence to the new access rules.

src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/student/FileSystemAccessPenguin.java (11)

44-50: Method accessFileSystemViaFileInputStream looks good.

The method is straightforward and uses a valid file path.


55-62: Method accessFileSystemViaFileOutputStream looks good.

The method is straightforward and uses a valid file path.


67-79: Method accessFileSystemViaFileReader looks good.

The method is straightforward and uses a valid file path.


84-93: Method accessFileSystemViaFileWriter looks good.

The method is straightforward and uses a valid file path.


98-113: Method accessFileSystemViaRandomAccessFile looks good.

The method is straightforward and uses a valid file path.


118-143: Method accessFileSystemViaFile looks good.

The method is straightforward and uses a valid file path.


234-250: Method accessFileSystemViaFileSystem looks good.

The method is straightforward and does not use null for file paths.


272-295: Method accessFileSystemViaPath looks good.

The method is straightforward and uses valid file paths.


300-309: Method accessFileSystemViaPaths looks good.

The method is straightforward and uses valid file paths.


314-325: Method accessFileSystemViaWatchService looks good.

The method is straightforward and does not use null for file paths.


360-369: Method accessFileSystemViaFileHandler looks good.

The method is straightforward and uses valid file paths.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ee9d55 and 7ff0b65.

Files selected for processing (1)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ff0b65 and 50c2f40.

Files selected for processing (4)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (1 hunks)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/JavaArchitectureTestCaseCollection.java (1 hunks)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java (4 hunks)
  • src/main/resources/archunit.properties (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/archunit.properties
Additional comments not posted (8)
src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (3)

4-6: LGTM!

The new import statements for JavaClasses and ImportOption are necessary and appropriate for the new implementation.


19-26: LGTM! Consider improving readability.

The declaration and initialization of allClasses are correct. For better readability, consider chaining the import options more clearly.

-        allClasses = new ClassFileImporter()
-                .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
-                .withImportOption(location -> location.toString().contains("jrt:/"))
-                .importClasspath();
+        allClasses = new ClassFileImporter()
+                .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
+                .withImportOption(location -> location.toString().contains("jrt:/"))
+                .importClasspath();

34-39: LGTM!

The tryResolve method correctly uses allClasses to resolve the class and handles exceptions appropriately.

src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/JavaArchitectureTestCaseCollection.java (1)

50-50: Verify the removal of banned packages.

The removal of "sun.security" and "java.awt.desktop" packages likely indicates a change in security or functionality requirements. Ensure that this change is intentional and does not introduce security risks.

Verification successful

Verified the removal of banned packages.

The removal of sun.security and java.awt.desktop packages from the banned list is confirmed to be safe as there are no occurrences of these packages in the codebase or configuration/documentation files.

  • No occurrences of sun.security or java.awt.desktop found in the codebase.
  • No mentions of sun.security or java.awt.desktop found in configuration or documentation files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of banned packages.

# Test: Search for the usage of the removed packages. Expect: No occurrences of the removed packages.
rg --type java 'sun.security|java.awt.desktop'

Length of output: 48


Script:

#!/bin/bash
# Description: Verify the removal of banned packages in configuration or documentation files.

# Test: Search for mentions of the removed packages in configuration or documentation files.
rg 'sun.security|java.awt.desktop' --glob '*.{yml,yaml,json,md,xml,properties}'

Length of output: 81

src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/TransitivelyAccessesMethodsCondition.java (4)

30-39: LGTM!

The bannedClasses set includes fundamental Java classes and packages, which streamlines access violation checks.


52-55: LGTM!

The declaration and initialization of customClassResolver are correct and use the CustomClassResolver class appropriately.

Also applies to: 77-77


166-186: LGTM!

The method getDirectAccessTargetsOutsideOfAnalyzedClasses correctly checks if the accessed class is part of bannedClasses and resolves target owners using customClassResolver.


199-201: LGTM!

The method resolveTargetOwner correctly uses customClassResolver to resolve class names, improving the efficiency of access checks.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50c2f40 and 9577966.

Files selected for processing (2)
  • .github/workflows/maven.yml (1 hunks)
  • src/main/resources/logback.xml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/maven.yml
Additional comments not posted (1)
src/main/resources/logback.xml (1)

15-15: LGTM! Ensure the new logger is used as intended.

The addition of the logger for com.tngtech.archunit with a logging level set to INFO is a good enhancement for better logging granularity.

Verify that the new logger is effectively utilized in the codebase.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9577966 and afa652e.

Files selected for processing (2)
  • src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (1 hunks)
  • src/main/resources/archunit.properties (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/archunit.properties
Additional comments not posted (4)
src/main/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.java (4)

4-4: LGTM! The import statement is necessary.

The import statement for JavaClasses is required for the new allClasses variable.


17-17: LGTM! The variable declaration is necessary.

The new instance variable allClasses is required to hold all imported classes.


19-25: Consider addressing the memory efficiency concern.

The constructor imports all classes, which might not be memory efficient. The TODO comment suggests improving this.

Ensure that the memory efficiency concern is addressed in future updates.


33-38: LGTM! The method change is appropriate.

The tryResolve method now directly accesses allClasses to resolve classes, handling cases where the class may not exist by returning an empty Optional.

Copy link
Collaborator

@MarkusPaulsen MarkusPaulsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good

@MarkusPaulsen MarkusPaulsen merged commit 6e44ca2 into main Aug 5, 2024
1 check passed
@MarkusPaulsen MarkusPaulsen deleted the feature/github-workflow-maven branch August 5, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Workflow for Java Maven Project
3 participants